/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PM;

import csse3004.GD.DA.PollMasterDA;
import csse3004.GD.Poll;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

/**
 *
 * @author David Bullock 42062222
 */
public class homeController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());
    private PollMasterService service = new PollMasterDA();

    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) {
        logger.info("returning mastar's home");

        int userID = Integer.parseInt((String) hsr.getSession().getAttribute("userID"));
        ArrayList<Poll> pollList = new Poll().genTestPoll();
        if (service.database) {
            pollList = service.getPolls(userID);
        }
        ModelAndView mav = new ModelAndView("home", "polls", pollList);
        return mav;
    }
}
